public class BinarySearch {
    public static void main(String[] args) {
        int []arr={1,3,5,7,9,11,13,15,17,19};
        System.out.println(binarySearch(arr,19));
    }

    public static int binarySearch(int []array,int target){
        int R=array.length-1;
        int L=0;
        while(L<=R){
            int n=(L+R)/2;
            if(target==array[n]){
                return n;
            } else if (target<array[n]) {
                R=n-1;
            } else {
                L=n+1;
            }
        }
        return -1;
    }
}
